package web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.Member;
import service.MemberService;
import serviceimpl.MemberServiceIpmt;

@WebServlet("/CheckUserServlet")
public class CheckUserServlet extends HttpServlet {
    private MemberService msi=new MemberServiceIpmt();
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username = request.getParameter("username");
//		Boolean isExists=msi.checkUserByUsername(username);
		Member member= msi.getMemberByUsername(username);
//		System.out.println(member);
		Boolean isExists=false;
		if(member!=null) {
			isExists=true;
		}
		//{"isExist":isExists}
//		response.getWriter().write("{\"isExist\":isExists}");
		response.setContentType("text/plain;charset=utf-8");
		response.getWriter().write("{\"isExists\": "+isExists+"}");
	}
	

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}